package org.dizena.modules.master.web;

import org.apache.commons.lang3.StringUtils;
import org.dizena.base.avo.req.JqGridReq;
import org.dizena.base.avo.resp.JqGridResp;
import org.dizena.modules.master.bean.Res;
import org.dizena.modules.master.service.RessService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("master/ress")
public class MasterRessController
{

    @Resource
    private RessService ressService;


    @GetMapping("list")
    public String list(Model m)
    {

        return "master/ress/list";
    }

    @PostMapping("list")
    @ResponseBody
    public JqGridResp<Res> list(@RequestParam(value = "resPid", required = false) String resPid, JqGridReq req)
    {

        if (StringUtils.isEmpty(resPid))
        {
            resPid = "0";
        }
        String[] keys = {"resPid"};
        Object[] values = {resPid};

        return ressService.list(req, keys, values);
    }

    @PostMapping("crud")
    @ResponseBody
    public String crud(String oper, Res ress)
    {
        return ressService.crud(oper, ress);
    }

    //取得最大的序号+1
    @RequestMapping("queryMaxSort")
    @ResponseBody
    public Integer queryMaxSort(String pid)
    {
        return ressService.queryMaxSort(pid);
    }

    // 取得父级菜单
    @RequestMapping("queryParentRes")
    @ResponseBody
    public List<Res> queryParentRes(@RequestParam("l") Integer level)
    {
        return ressService.queryParentRes(level);
    }


}
